package com.zjw.wsexample.controller;

import com.zjw.model.R;
import com.zjw.model.enums.ClientType;
import com.zjw.model.pojo.vo.MessageVO;
import com.zjw.model.pojo.vo.WsNodeInfo;
import com.zjw.starter.fegin.RemoteRegisterService;
import com.zjw.starter.service.MessageService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;

@RestController
public class HelloController {

    @Resource
    private RemoteRegisterService remoteRegisterService;
    @Resource
    private MessageService messageService;

    @GetMapping("/hello")
    public R<Collection<WsNodeInfo>> hello(@RequestParam String groupId, @RequestParam String userId) {
        MessageVO messageVO = new MessageVO();
        messageVO.setGroupId(groupId);
        messageVO.setFrom("2");
        messageVO.setTo(userId);
        messageVO.setContent("hello world!");
        messageVO.setClientTypes(Collections.singleton(ClientType.APP));
        R<MessageVO> result = messageService.sendMessageToUser(messageVO);
        System.out.println(result.getCode());
        return remoteRegisterService.getServersByUserId(groupId, userId);
    }
}
